package com.example.home.hospital.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.hospital.activity.RegistrationMainActivity;
import com.example.home.hospital.bean.AllCardBean;
import com.example.home.hospital.bean.RegistrationBean;
import com.google.gson.Gson;

import java.util.Collections;
import java.util.List;

public class RegistrationAdapter extends RecyclerView.Adapter<RegistrationAdapter.MyHoldy> {

    private Context context;
    public  List<RegistrationBean.RowsBean> list;
    public  List<AllCardBean.RowsBean> rowsBean;
    private View view;

    public RegistrationAdapter(Context context, List<RegistrationBean.RowsBean> list, AllCardBean.RowsBean rowsBean) {
        this.context = context;
        this.list = list;
        this.rowsBean = rowsBean != null ? Collections.singletonList(rowsBean) : null;
    }




    @NonNull
    @Override
    public MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_regis,null);
        return new MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHoldy holder, int position) {
        holder.categoryName.setText("类型：" + list.get(position).getCategoryName());
        holder.money.setText("挂号费：" + list.get(position).getMoney());
        holder.rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    Intent intent = new Intent(context, RegistrationMainActivity.class);
                    Gson gson = new Gson();
                    intent.putExtra("regisId1", gson.toJson(list.get(position)));
                    intent.putExtra("regisid2", gson.toJson(rowsBean.get(position)));
                    context.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyHoldy extends RecyclerView.ViewHolder {

        private ImageView img;
        private TextView categoryName;
        private TextView money;
        private RelativeLayout rootView;




        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.img);
            categoryName = itemView.findViewById(R.id.categoryName);
            money = itemView.findViewById(R.id.money);
            rootView = itemView.findViewById(R.id.rootView);
        }
    }
}
